<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="org.apache.shiro.SecurityUtils" %>
<%@ page import="com.topisv.tms.service.account.ShiroDbRealm.ShiroUser" %>

<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
<script type="text/javascript">
  
  var dataTables_working;   //dataTables-作业中订单 
  
  $(function() {
		$("#queryForm").validate();
		$("#inputForm").validate();
		
		$("#add").hide();
		
		//初始化日期选择框
		var now = new Date();
		var today=(now.getFullYear())+"/"+(now.getMonth()<10? "0"+(now.getMonth()+1):now.getMonth())+"/"+(now.getDate()<10? "0"+now.getDate():now.getDate());    
		$("#_dataRange").val(today+"-"+today);
		$("#_dataRange").daterangepicker({format: 'YYYY/MM/DD',dateLimit :{days : 31}});

		//bindCheckBox("alreadyMyCheckedAll","alreadyMyChecked");
		
		$("#alreadyMyCheckedAll").on("ifChecked", function(event) {
			var eachNum = 0;
			$('#table_working .checkChosen').each(function() {
				$(this).iCheck('check');
				eachNum++;
				if (eachNum == 10) {
					return false;
				}
			});
		});
		$("#alreadyMyCheckedAll").on("ifUnchecked", function(event) {
			$('#table_working .checkChosen').each(function() {
				$(this).iCheck('uncheck');
			});
		});
		
        });
  
  //初始化dataTables
  function initTable(){
  	 dataTables_working=$("#table_working").dataTable({
	     "bServerSide":true,
	     "sAjaxSource":'${ctx}/v2/expressNoInput/loadData',
	     "fnServerData": retrieveData_working,
	     "bFilter": false,
	     "bSort": false,
	     "sZeroRecords": "查询无记录！",
	     "bProcessing": true,
	     "oLanguage": {
	         "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	      },
	      "aoColumns": [
				{"mData": 'id',
				    "render":function(obj){
				    	 //return "<input type='checkbox' name='alreadyMyChecked' id='check_already" + obj + "' value='" + obj + "' onclick='alreadyMyChecked(" + obj + ")' />";
				    	 return "<input type=\"checkbox\" name=\"alreadyMyChecked\" id=\"check_already"+obj+"\" value="+obj+" class=\"checkChosen icheckbox_minimal\" \"/>";
				     }
				},      
              {"mData": null,
              	 "mRender": function (data, display, row) {
	              		<c:forEach items="${customerList}" var="customer">
							if("${customer.customerCode}" == row.customerCode){
								return "${customer.customerName}";
							}
						</c:forEach>
						return "";
		           }
              },
              {
                "mData": 'order',
                "render":function(obj){
                  return "<a href='${ctx}/orderMsg/v2_orderMsgDetail/"+obj.ordeno+"' title='查看订单信息' target='_blank'>"+obj.ordeno+"</a>";
                }
              },
              {"mData": 'customerOrderno'},
              {"mData": 'expressCompany'},
              {"mData": 'expressNo',
               "render":function(obj,type,full){
              	return full.expressNo||full.ebillNo;
              }},
              {
                "mData": 'billType',
                "render": function (obj) {
                   var billType=obj;
                   if(billType=='cbill'){
                     return "普通面单";
                   }else if(billType=='ebill'){
                     return "电子面单";
                   }else{
                     return "";
                   }
                }
              },
              {"mData": 'warehouseCode'},
              {"mData": 'batchCode',
               "render":function(obj){
                      return "<a href='${ctx}/workMsg/v2_workMsgDetail/"+obj+"' title='查看批次信息' target='_blank'>"+obj+"</a>";
                }
              },
              {"mData": 'taskCode',
               "render":function(obj){
                      return "<a href='${ctx}/orderMsg/v2_queryOrderMsg?_taskCode="+obj+"' title='查看任务信息' target='_blank'>"+obj+"</a>";
                 }
              },
              {
                "mData": 'inputTime',
                    "render": function (obj) {
                  	  var time=obj.time;
                       var date = new Date(time);
                       return date.Format("yyyy-MM-dd hh:mm");
                    }
              },
              {
                "mData": 'status',
                "render": function (obj) {
                   var status=obj;
                   if(status=='1'){
                     return "创建批次";
                   }else if(status=='2'){
                     return "创建任务";
                   }else if(status=='3'){
                     return "已拣货";
                   }else if(status=='4'){
                     return "已灯光拣选";
                   }else if(status=='5'){
                     return "已包装";
                   }else if(status=='6'){
                     return "已发货";
                   }else if(status=='9'){
                     return "待包装";
                   }else if(status=='0'){
                     return "待创建批次";
                   }else{
                     return "";
                   }
                }
              }
          ]
 	   });
  	   return dataTables_working;
  	}   
	//查询
	function query(){
		var dataRange=$("#_dataRange").val();
		  if(dataRange.length==0){
		     alert("请选择日期范围...");
		     return;
		  }
		   
		if($("#queryForm").valid()){
			if (dataTables_working) {
				dataTables_working.fnDestroy();
			}
			initTable();
		}
	}
	
	//回调函数_作业中
	function retrieveData_working( sSource, aoData, fnCallback ) { 
	   
	   //查询参数
	   aoData.push( { "name": "customerCode", "value": $("#_customerCode").val() } );  
	   aoData.push( { "name": "warehouseCode", "value": $("#_warehouseCode").val() } );
	   aoData.push( { "name": "dataRange", "value": $("#_dataRange").val() } );
	   aoData.push( { "name": "orderno", "value": $("#_orderno").val() } );
	   aoData.push( { "name": "cacode", "value": $("#_logistics").val() } );
	   aoData.push( { "name": "expressNo", "value": $("#_expressNo").val() } );
	   aoData.push( { "name": "status", "value": $("#_status").val() } );
	   aoData.push( { "name": "batchCode", "value": $("#_batchCode").val() } );
	   aoData.push( { "name": "taskCode", "value": $("#_taskCode").val() } );
	    
	   $.ajax({ 
	       "type": "post",
	       "contentType": "application/json", 
	       "url": sSource,    
	       "dataType": "json",   
	       "data": JSON.stringify(aoData),
	       "success": function(resp) {  
	       			fnCallback(resp);
	       			$("#total_working").html("("+resp.iTotalRecords+")");
	       		}
	   });    
	}
	
	//显示导入对话框
	function showDialog(){
     	$('.import-excel').modal('show');	
		
	}
	
	function fullbgDialog(){
		if($("#file").val()==""){
			alert("请选择文件！");
			return false;
		}else{
			var param1 = $("#_customerCode1").val()=="" ? " ":$("#_customerCode1").val();
			var param2 = $("#_warehouseCode1").val()=="" ? " ":$("#_warehouseCode1").val();
			var param3 = $("#_logistics1").val()=="" ? " ":$("#_logistics1").val();
			var str = "${ctx}/v2/expressNoInput/exprssNoInputToWorkOrder/" + param1 + "/"+ param2 +"/"+ param3;
			$("#inputForm").attr("action", str);
			$("#inputForm").submit();
			
		}
	}
	
/* 	function alreadyMyChecked(item) {
		if ($("#check_already" + item).is(":checked")) {

		} else {
			$("#alreadyMyCheckedAll").attr("checked", false);
		}
	} */
	
	function alreadyMyCheckedAllTWS() {
		var tempChecked = "";
		$("input[type='checkbox'][name='alreadyMyChecked']:checked").each(function() {
		     if(tempChecked==""){
		        tempChecked=$(this).val();
		     }else{
		       tempChecked = tempChecked + "," + $(this).val();
		     }
		});
		return tempChecked;
	}
	
	//标记为已打印
	function markPrintred(){
		showBg();
		var ids = alreadyMyCheckedAllTWS();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressNoInput/markPrintred',
			data : {
				ids:ids
			},
			dataType : 'json',
			success : function(data) {
				closeBg();
				if(data.status=="1"){
					jAlert(data.content);
				}
			},
			error : function() {
				closeBg();
				jAlert(data.content);
			}
		});
	}
</script>
</head>

<body>
<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>

<section class="content">
    <!-- 查询条件  start-->
   	<div class="row">
	<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary" >
			    
				<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
				</div>
				
				<div class="box-body">
				    <form class="form-search" id="queryForm" method="post" >
				    <!-- 第一行 -->
					<div class="form-group row">
					
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 商家： </span> 
								<select data-placeholder="请选择..." class="form-control searchSelect" id="_customerCode" name="_customerCode" onchange="ajaxAreaGroup2(this,'_warehouseCode')">
									<option value=""></option>
									<c:forEach items="${customerList}" var="customer">
										<option value="${customer.customerCode}"
											<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 仓库： </span> 
								<select class="form-control span3 required" id="_warehouseCode" name="_warehouseCode">
									<option value=""></option>
									<c:forEach items="${warehouseList}" var="warehouse">
										<option value="${warehouse.groupCode}" >${warehouse.groupName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 订单编号： </span> 
								<input type="text" class="form-control" id="_orderno" name="_orderno">
							</div>
						</div>
						
						<div class="col-sm-3">
								<div class="input-textgroup col-sm-12">
								<span class="input-group-text">作业状态:</span>
								<select  class="form-control" id="_status" name="_status" >
								        <option value="" <c:if test="${param._status eq ''}">selected="selected"</c:if>>全选</option>
								        <option value="1" <c:if test="${param._status eq '1'}">selected="selected"</c:if>>创建批次</option>
								        <option value="2" <c:if test="${param._status eq '2'}">selected="selected"</c:if>>创建任务</option>
								        <option value="3" <c:if test="${param._status eq '3'}">selected="selected"</c:if>>已拣货</option>
								        <option value="4" <c:if test="${param._status eq '4'}">selected="selected"</c:if>>已灯光拣选</option>
								        <option value="5" <c:if test="${param._status eq '5'}">selected="selected"</c:if>>已包装</option>
								        <option value="6" <c:if test="${param._status eq '6'}">selected="selected"</c:if>>已发货</option>
								        <option value="9" <c:if test="${param._status eq '9'}">selected="selected"</c:if>>待包装</option>
								</select> 
								</div>
						</div>
						
					</div>

                    <!-- 第二行 -->
					<div class=" form-group row">
						<div class="col-sm-6">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 导入时间： </span>

								<div class="input-group">
									<div class="input-group-addon">
										<i class="fa fa-calendar"></i>
									</div>
									<input type="text" class="form-control pull-right" id="_dataRange" name="_dataRange" value="${param._fromDate}"/>
								</div>
								
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 快递公司： </span> 
								<select class="form-control span3" id="_logistics" name="_logistics">
									<option value=""></option>
									<c:forEach items="${logisticsList}" var="logistics">
										<option value="${logistics.companyCode}" >${logistics.companyName}</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 快递单号： </span> 
								<input type="text" class="form-control" id="_expressNo" name="_expressNo">
							</div>
						</div>
						
					</div>
					 <!-- 第三行 -->
					<div class=" form-group row">
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 作业批次： </span> 
								<input type="text" class="form-control" id="_batchCode" name="_batchCode">
							</div>
						</div>
						
						<div class="col-sm-3">
							<div class="input-textgroup col-sm-12">
								<span class="input-group-text"> 作业任务： </span> 
								<input type="text" class="form-control" id="_taskCode" name="_taskCode">
							</div>
						</div>
						
						<div class="col-sm-1">
							<button class="btn btn-primary" type="button" onclick="query();">搜 索</button>
						</div>
						<div class="col-sm-1">
							<div class="btn btn-primary" id="importSet" onclick="showDialog();">快递单号导入</div>
						</div>
						
					</div>
					</form>
				</div>

			</div>

	 </div>
	</div>
    <!-- 查询条件 end -->
  	
	<button class="btn btn-primary" id="importSet" onclick="markPrintred();" style="margin-bottom: 20px;">标记为已打印</button>

    <!-- 查询结果 start-->
	<div class="form-group row">
			<div class="col-md-12">
				<div class="box box-solid box-primary">
					<div class="box-header">
						<i class="fa fa-list"></i>
						<h3 class="box-title">数据列表</h3>
						<div class="box-tools pull-right">
							<button class="btn btn-primary btn-sm" data-widget="collapse" type="button">
								<i class="fa fa-minus"></i>
							</button>
						</div>
					</div>
					<div class="box-body">
						<table id="table_working" class="table table-striped table-bordered table-condensed">
							<thead>
								<tr>
					             	<th style="width: 20px;"><input type="checkbox" name="alreadyMyCheckedAll"
										id="alreadyMyCheckedAll" onclick="check_all(this,'alreadyMyChecked');" />
				                 	<th style="width: 50px;">商家</th>
								    <th style="width: 100px;">能容订单号</th>
								    <th style="width: 100px;">商家订单号</th>
								    <th style="width: 100px;">快递公司</th>
								    <th style="width: 100px;">快递单号</th>
								    <th style="width: 100px;">运单类型</th>
								    <th style="width: 50px;">仓库</th>
								    <th style="width: 100px;">作业批次</th>
								    <th style="width: 100px;">作业任务</th>
								    <th style="width: 100px;">导入时间</th>
								    <th style="width: 100px;">作业状态</th>
					             </tr>
							</thead>
							<tbody>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	<!-- 查询结果 end -->
	
	
	<!-- 弹出窗体-导入运单 start -->
		<div class="modal fade import-excel" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
			<div class="modal-dialog" style="width: 60%;">
				<div class="modal-content">
					<div class="modal-body">
						<div class="box box-solid box-primary">
				      		<div class="box-header" id="importTitle"><span class="box-title">快递单号导入</span></div>
							<div class="box-body">
								<form id="inputForm"  method="post" enctype="multipart/form-data">
									<div class="form-group row">
						
										<div class="col-sm-3">
											<div class="input-textgroup col-sm-12">
												<span class="input-group-text"> 商家： </span> 
												<select data-placeholder="请选择..." class="form-control searchSelect required" id="_customerCode1" name="_customerCode1" onchange="ajaxAreaGroup2(this,'_warehouseCode1')">
													<option value=""></option>
													<c:forEach items="${customerList}" var="customer">
														<option value="${customer.customerCode}"
															<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>>${customer.customerName}</option>
													</c:forEach>
												</select>
											</div>
										</div>
										
										<div class="col-sm-3">
											<div class="input-textgroup col-sm-12">
												<span class="input-group-text"> 仓库： </span> 
												<select class="form-control span3 required" id="_warehouseCode1" name="_warehouseCode1">
													<option value=""></option>
													<c:forEach items="${warehouseList}" var="warehouse">
														<option value="${warehouse.groupCode}" >${warehouse.groupName}</option>
													</c:forEach>
												</select>
											</div>
										</div>
										
										<div class="col-sm-3">
											<div class="input-textgroup col-sm-12">
												<span class="input-group-text"> 快递公司： </span> 
												<select class="form-control span3 required" id="_logistics1" name="_logistics1">
													<option value=""></option>
													<c:forEach items="${logisticsList}" var="logistics">
														<option value="${logistics.companyCode}" >${logistics.companyName}</option>
													</c:forEach>
												</select>
											</div>
										</div>
									</div>
									
									<table class="table table-striped table-bordered table-condensed">
										<tbody>
											<tr>
												<td>
													<input name="file" id="file" class="btn required"  type="file"/>
												</td>
											</tr>
											<tr>
												<td style="height: 50px; vertical-align: middle;">
													<input id="submit_btn" class="btn btn-primary" type="button" onclick="fullbgDialog();" value="提交" />
													<input type="reset" class="btn"  />
												</td>
											</tr>
									  </tbody>
								   </table>
							   </form>
							</div>
						</div>
					</div>	
				</div>	
			</div>
		</div>
	<!-- 弹出窗体-导入运单 end  -->
	</section>
</body>
</html>